package com.xian.im.modules.mis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-02-05 10:19
 **/
@Slf4j
@Component
public class LimitJob {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *  清理所有的请求IP 每天零点清理
     */
    @Scheduled(cron = "0 0 0 */1 * ? ")
    public void limitParamReset() {
        Set keys = redisTemplate.keys(LimitProcess.KEY + "*");
        log.info("重置限流规则 {}",keys);
        redisTemplate.delete(keys);
    }
}
